<?php
$this->pageTitle = 'Zoznam ponúk/dopytov';
?>

<div class="listing">
	<h3>Zoznam ponúk/dopytov</h3>
	<table class="list">
		<thead>
			<tr>
				<th class="identifier"><?php echo $this->Paginator->sort('id', 'ID'); ?></th>
				<th><?php echo $this->Paginator->sort('description', 'Popis'); ?></th>
				<th class="col50"><?php echo $this->Paginator->sort('type', 'Typ'); ?></th>
				<th class="col50"><?php echo $this->Paginator->sort('status', 'Stav'); ?></th>
				<?php if (in_array($showPersonColumns, array(0))): ?>
				<th class="col100"><?php echo $this->Paginator->sort('fk_client_id', 'Klient'); ?></th>
				<?php endif; ?>
				<?php if (in_array($showPersonColumns, array(0, 1))): ?>
				<th class="col100"><?php echo $this->Paginator->sort('fk_tipster_id', 'Tiper'); ?></th>
				<?php endif; ?>
				<?php if (in_array($showPersonColumns, array(0))): ?>
				<th class="col100"><?php echo $this->Paginator->sort('fk_broker_id', 'Maklér'); ?></th>
				<?php endif; ?>
				<?php if (in_array($showPersonColumns, array(1))): ?>
				<th class="col100"><?php echo $this->Paginator->sort('commission', 'Odmena za tip (min.)'); ?></th>
				<?php endif; ?>
				<?php if (isset($userPermissions['market']['view']) || isset($userPermissions['market']['edit']) || isset($userPermissions['market']['delete'])): ?>
				<th class="action"><?php echo 'Akcie'; ?></th>
				<?php endif; ?>
			</tr>
		</thead>
		<tbody>
			<?php
			foreach ($markets as $market):
			?>
			<tr>
				<td class="number">
					<?php echo $market['Market']['id']; ?>
				</td>
				<td>
					<?php echo $market['Market']['html_description']; ?>
				</td>
				<td>
					<?php echo ($market['Market']['type'] == 1 ? 'dopyt' : 'ponuka'); ?>
				</td>
				<td class="<?php echo Market::getStatusColor($market['Market']['status']); ?>">
					<?php echo Market::getStatusText($market['Market']['status']); ?>
				</td>
				
				<?php if (in_array($showPersonColumns, array(0, 2))): ?>
				<td>
					<?php
					if (isset($userPermissions['market']['view'])) {
						echo $this->Html->link(htmlspecialchars($market['Client']['full_name']), array('controller' => 'person', 'action' => 'view', $market['Client']['id']));
					} else {
						echo $market['Client']['full_name'];
					}
					?>
				</td>
				<?php endif; ?>
				<?php if (in_array($showPersonColumns, array(0, 1))): ?>
				<td>
					<?php
					if (isset($userPermissions['market']['view'])) {
						echo $this->Html->link(htmlspecialchars($market['Tipster']['full_name']), array('controller' => 'person', 'action' => 'view', $market['Tipster']['id']));
					} else {
						echo $market['Tipster']['full_name'];
					}
					?>
				</td>
				<?php endif; ?>
				<?php if (in_array($showPersonColumns, array(0))): ?>
				<td>
					<?php
					if (isset($userPermissions['market']['view'])) {
						echo $this->Html->link(htmlspecialchars($market['Broker']['full_name']), array('controller' => 'person', 'action' => 'view', $market['Broker']['id']));
					} else {
						echo $market['Broker']['full_name'];
					}
					?>
				</td>
				<?php endif; ?>
				<?php if (in_array($showPersonColumns, array(1, 2))): ?>
				<td class="number">
					<?php
						if ($market['Market']['status'] == Market::STATUS_IN_PROCESS) {
							echo number_format($personType['PersonType']['commission_2_tipsters'] * $market['Market']['commission'] / 100, 2, ',', ' ');
						} elseif ($market['Market']['status'] == Market::STATUS_FINISHED_SUCCESSFULLY) {
							echo number_format($myCommissions[$market['Market']['type']][$market['Market']['id']], 2, ',', ' ');
						} else {
							echo '-';
						}
					?>
				</td>
				<?php endif; ?>
				<?php if (isset($userPermissions['market']['view']) || isset($userPermissions['market']['edit']) || isset($userPermissions['market']['delete'])): ?>
				<td>
					<?php
						if (isset($userPermissions['market']['view'])) {
							echo $this->Html->link(__('View', true), array('action' => 'view', $market['Market']['id']), array('class' => 'show'));
						}
					?>
					<?php
						if (isset($userPermissions['market']['edit'])) {
							echo $this->Html->link(__('Uprav', true), array('action' => 'edit', $market['Market']['id']), array('class' => 'edit'));
						}
					?>
					<?php
						if (isset($userPermissions['market']['delete'])) {
							echo $this->Html->link(__('Delete', true), array('action' => 'delete', $market['Market']['id']), array('class' => 'delete'), __('Ste si istý, že chcete odstrániť záznam?', true));
						}
					?>
				</td>
				<?php endif; ?>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>

	<?php if ($this->Paginator->hasPage(2)): ?>
		<div class="pager">
			<?php echo $this->Paginator->prev('<< '.__('predchádzajúca', true), array(), null, array('class'=>'disabled')); ?>
			<?php echo $this->Paginator->numbers(); ?>
			<?php echo $this->Paginator->next(__('ďalšia', true).' >>', array(), null, array('class' => 'disabled')); ?>
		</div>
	<?php endif; ?>
</div>